//
//  PositionsCell.m
//  Futures
//
//  Created by Cheng on 2017/6/27.
//  Copyright © 2017年 Cheng. All rights reserved.
//

#import "PositionsCell.h"

@implementation PositionsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setCellWith:(HoldingModel *)model{
    self.title.text = model.Symbol;
    
    NSString *buySell;
    if ([model.BuySell containsString:@"买"]) {
        buySell = [NSString stringWithFormat:@"看涨%d手",model.Qty];
        self.buySellDirection.backgroundColor = [UIColor redColor];
    }else{
        buySell = [NSString stringWithFormat:@"看跌%d手",abs(model.Qty)];
        self.buySellDirection.backgroundColor = [UIColor greenColor];
    }
    self.buySellDirection.layer.borderColor = self.buySellDirection.backgroundColor.CGColor;
    
    [self.buySellDirection setTitle:buySell forState:UIControlStateNormal];
    self.openPrice.text = NSStringFromFloat(model.avgPrice);
    self.nowPrice.text = NSStringFromFloat(model.MarketPrice);
    
    if (model.UnrealizedPL < 0) {
        NSString *str = [NSString stringWithFormat:@"%.0f 元",model.UnrealizedPL];
        self.profit.attributedText = [NSString stringWithaString:str bigFont:21 smallFont:15 color:[UIColor greenColor]];
//        self.profit.textColor = [UIColor greenColor];
    }else if (model.UnrealizedPL > 0){
        NSString *str = [NSString stringWithFormat:@"+%.0f 元",model.UnrealizedPL];
        self.profit.attributedText = [NSString stringWithaString:str bigFont:21 smallFont:15 color:[UIColor redColor]];
//        self.profit.textColor = [UIColor redColor];
    }else{
        NSString *str = [NSString stringWithFormat:@"+%.0f 元",model.UnrealizedPL];
        self.profit.attributedText = [NSString stringWithaString:str bigFont:21 smallFont:15 color:[UIColor whiteColor]];
    }
    
    
    
}

@end
